//
//  XQUpgradeViewController.m
//  XQBluetoothSDK
//
//  Created by 包月兴 on 16/8/8.
//  Copyright © 2016年 包月兴. All rights reserved.
//

#import "XQUpgradeViewController.h"
#import "XQBluetoothSDK.h"
#import "AKTKit.h"
@interface XQUpgradeViewController ()
@property (nonatomic,copy) UILabel *messageLabel; //提示信息
@property (nonatomic,copy) UIProgressView *progressView; //升级进度
@end

@implementation XQUpgradeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self p_initUI];
    _messageLabel = self.messageLabel;
    _progressView = self.progressView;
    [self p_initUI];
    [self p_initFunction];
}

-(void)p_initUI
{
   self.title = @"升级";
}


-(void)p_initFunction
{
    
    [XQBleSDKInstance upgradeWithProgress:^(int progress) {
        _progressView.progress = progress/100;
        _messageLabel.text = [NSString stringWithFormat:@"%d%%",progress];
    } no:^{
        _messageLabel.text =  @"无最新固件";;
    } success:^{
         _messageLabel.text = @"升级完成";
    } failure:^(XQBluetoothError *error) {
        _messageLabel.text = @"升级失败";
    }];
}



-(UILabel *)messageLabel
{
    if (_messageLabel == nil) {
        _messageLabel = [[UILabel alloc] init];
        CGFloat width = 100;
        CGFloat x = (mAKT_SCREENWITTH - width)/2.0;
        CGFloat y = 64 + 20;
        _messageLabel.x = x;
        _messageLabel.y = y;
        _messageLabel.width = width;
        _messageLabel.height = 20;
        _messageLabel.text = @"升级中";
        [self.view addSubview:_messageLabel];
    }
    return _messageLabel;
}

-(UIProgressView *)progressView
{
    if (_progressView == nil) {
        _progressView = [[UIProgressView alloc] init];
        CGFloat width = 200;
        _progressView.x =  (mAKT_SCREENWITTH - width)/2.0;
        _progressView.y = _messageLabel.y + 20 +10;
        _progressView.width = width;
        _progressView.height = 10;
        _progressView.progressViewStyle = UIProgressViewStyleDefault;
        [self.view addSubview:_progressView];
    }
    return _progressView;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
